<?php

/***  DOCUMENTATION LAYER

Last Update: Jun 2007
	
DESCRIPTION
	a test of Greqo Analytics class -- retrieves account and profile lists
	
NOTES
	Check path to analytics.class.php.  Add a login.inc.php file to directory
	with appropriate $_GRQ array settings, or set access properties directly
	below.
	
	Set debug to 1 for blow-by-blow feedback

	3 sections to edit below:
		1. Meta Data
		2. Procedure Block
		3. Function
	
***/

/* -- EDIT THIS SECTION ----------------------------------------------------- */
// Some Meta Data
$page_title = 'Greqo Test';
$test_name = 'Greqo Analytics Class';
$run_procedure = 1;
$run_function = 0;
$num_cycles = 10;		// num of cycles to run function

// Include Files
require_once('../analytics.class.php');

/* -- END SECTION ----------------------------------------------------------- */



/* -- NO EDIT --------------------------------------------------------------- */
// Timer
$_tx0 = microtime();
// HEADER
$buffer = "<h1 style='margin:8px 0 0;'>$page_title</h1>";
$buffer .= "<h4 style='margin:0 0 16px;'>$test_name</h4>";	// put script name here
/* -- END SECTION ----------------------------------------------------------- */



/* -- EDIT THIS SECTION ----------------------------------------------------- */
// Procedural Testing

if ( $run_procedure ) 
{
	$buffer .= "<h4 style='margin:0; color:blue;'>Testing in Progess</h4>";
	
	// create object
	require_once('login.inc.php');
	$GreqoAnalytics = new GreqoAnalytics($debug=0);
	$GreqoAnalytics->email = $_GRQ['email'];
	$GreqoAnalytics->password = $_GRQ['password'];

	// get accounts
	$ACCOUNTS = $GreqoAnalytics->request_account_list();
	$adump = print_r($ACCOUNTS, 1);
	$buffer .= "<pre>$adump</pre>";
	
	// get profiles for a randomly selected account
	$KEYS = array_keys($ACCOUNTS);
	$acct_nm = $KEYS[array_rand($KEYS)];
	$acct_id = $ACCOUNTS[$acct_nm];
	$buffer .= "<h4 style='color:#c33;'>getting profile list for account: {$acct_nm}</h4>";
	$PROFILES = $GreqoAnalytics->request_profile_list($acct_id);
	$adump = print_r($PROFILES, 1);
	$buffer .= "<pre>$adump</pre>";
}

/* -- END SECTION ----------------------------------------------------------- */



/* -- EDIT THIS SECTION ----------------------------------------------------- */
// Function Test
if ( $run_function )
{

// Add your function here
function function_name() 
{
// *** DATA

// *** MANIPULATE

// *** RETURN

} // end function


	// run function
	$buffer .= "<h2 style='margin:0; color:green;'>Function Test</h2>";	
	while ( $num_cycles )
	{
		// $result = function_name();
		$buffer .= "<h6 style='margin:0; color:#ccc;'>test #{$run} complete</h6>";
		$num_cycles--;
	}
}

/* -- END SECTION ----------------------------------------------------------- */





/* -- NO EDITING NEEDED BELOW THIS LINE-------------------------------------- */
// output page

// Footer
$_txn = microtime();
$stx = number_format(((substr($_txn,0,9)) + (substr($_txn,-10)) - (substr($_tx0,0,9)) - (substr($_tx0,-10))),4); 
$footer = <<<HTML
<h4 style="margin:0; position:absolute; top:6px; right:6px; font-family:monospace; color:#36f; padding:4px; border:1px solid #36f; font-weight:normal; background:#f3f6ff;">
script completed in $stx s
</h4>
HTML;
$buffer .= $footer;

// Dump Html
$html = <<<HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
<title>PHP Test: $page_title</title>
</head>
<body>
$buffer
</body>
</html>
HTML;

echo $html;

?>
